﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace Tank
{
    public enum PICKUP
    {
        Plasma,
        Electro
    }

    class PickUp : CircularSprite
    {
        private BoundingSphere spriteBS;
        private float radius;
        private float elasticity;
        private bool isActive;     //<-----When true the pick up is active and should not be seen on the board.  When false is drawn on the board. 
        private bool adjustScale;
        private PICKUP pickUp;
        private float scale;

        public PickUp(Vector2 _pos, float _maxVel, float _maxAccel, float _drag, string _textureID, string _name, float _radius, PICKUP pickup)
            : base(_pos, _maxVel, _maxAccel, _drag, _textureID, _name, _radius)
        {
            radius = _radius;
            elasticity = 1.0f;
            Vector3 center = new Vector3(_pos.X, _pos.Y, 0.0f);
            spriteBS = new BoundingSphere(center, radius);

            isActive = false;
            adjustScale = true;
            pickUp = pickup;
            scale = 0.25f;
        }

        public override void Update(float deltaTime)
        {
            base.Update(deltaTime);

            spriteBS.Center.X = Position.X;
            spriteBS.Center.Y = Position.Y;
        }

        //=============================================================
        // Draw 
        // Desc: Draws the pick up on the screen.
        //=============================================================
        public override void Draw(SpriteBatch spriteBatch)
        {
            if (!isActive)
            {
                Texture2D texture = World.Instance.GetTexture(TextureID);

                scale = GetScale();

                spriteBatch.Draw(texture, Position, null, Color.White, 0, new Vector2(0, 0), scale, 0, 0);
            }
        }

        public PICKUP GetPickUp
        {
            get { return pickUp; }
        }

        //=============================================================
        // GetScale 
        // Desc: Adjusts the scale factor when drawn.
        //=============================================================
        private float GetScale()
        {
            if (adjustScale)
            {
                if (scale <= 0.20f)
                {
                    adjustScale = false;
                }
                scale -= 0.005f;
                return scale;
            }
            else
            {
                if (scale >= 0.25f)
                {
                    adjustScale = true;
                }
                scale += 0.005f;
                return scale;
            }
        }

        //=============================================================
        // IsActive 
        // Desc: Sets whether the pick up is active or not.
        //=============================================================
        public bool IsActive
        {
            get { return isActive; }
            set { isActive = value; }
        }
    }
}
